var express = require('express'),
    // swig = require('swig-templates'),
    // request = require('request'),
    wx = require('../base/wx'),
    router = express.Router();

function getData(req, res, next) {
    var result = {
        "code": 200,
        "title": "iPhone48元系列",
        "message": [{
            "nav_id": 1,
            "name": "iPhone6/6s",
            "node_url": "/uploads/model/20170724/80e437d528557d8fd32dd0c2cd6b7533.jpg"
        }, {
            "nav_id": 2,
            "name": "iPhone6/6s plus",
            "node_url": "/uploads/model/20170724/4700484a15a26a3189505bdc96fdfe50.jpg"
        }, {
            "nav_id": 3,
            "name": "iPhone7",
            "node_url": "/uploads/model/20170724/d2ef933df500cc840f645b8ee5855465.jpg"
        }, {
            "nav_id": 4,
            "name": "iPhone7 plus",
            "node_url": "/uploads/model/20170724/c3e25e7b8747f3edc81e2f032fd7c49d.jpg"
        }, {
            "nav_id": 18,
            "name": "iPhone8 plus",
            "node_url": "/uploads/model/20180116/8a183cbf4bb2682bbcfaa5ed0fde027f.jpg"
        }, {
            "nav_id": 19,
            "name": "iPhone8",
            "node_url": "/uploads/model/20171116/2d59b1652d586578550327832ba415bb.jpg"
        }, {
            "nav_id": 20,
            "name": "iPhone x",
            "node_url": "/uploads/model/20180116/6a6be5a688c0c7fa78d7148dab0f4b0b.jpg"
        }],
        "imsg": "返回数据成功"
    };

    if (result.code == 200) {
        res.render('page/kind', {
            stupid_data: [{
                type: '',
                type_cn: result.title,
                list: result.message
            }]
        });
    }
    return;




    kakarotto.request.get({
        url: kakarotto.config.api.origin + '/index/index/brandMobiles?user_id=' + (req.cookies.user_id?req.cookies.user_id:'') + '&nav_id=' + req.query.id
    }, function (error, response, body) {
        try {
            var result = JSON.parse(body);
            if (result.code == 200) {
                res.render('page/kind', {
                    appTabTitle: [result.title],
                    list: result.message
                });
            }
        } catch (e) {
            var err = new Error('Not Found');
            err.status = 500;
            next(err);
            return;
        }
    });
}

router.get('/', function (req, res, next) {
    wx.goAccessToken(req, res, function () {
        getData(req, res, next);
    });
});

module.exports = router;
